import React, {useEffect, useState} from 'react';
import {Form} from "antd";
import FormLayout from "@/assets/components/formLayout";
import {modulesUrl} from "@/assets/constant/modulesUrl";
import {ProFormText} from "@ant-design/pro-form";
import Edit from "@/assets/components/edit";
import FormSwitch from "@/assets/components/formSwitch";
import Upload from "@/assets/components/upload";
import {Doc} from "@/pages/doc/DocList/data";
import {hooksSet} from "@/assets/utils/utils";

const DocForm: React.FC<{}> = (props) => {

  // @ts-ignore
  const id = props.match.params.id;
  // @ts-ignore
  const type = props.match.params.type;
  const [form] = Form.useForm();

  // 根据类型获取类型名称
  let typeName = "";
  switch(type){
    case "1":
      typeName = "报表文件";
      break;
    case "2":
      typeName = "埋点文档";
      break;
  }

  const [data, setData] = useState<Doc>()

  /**
   * 启动加载
   */
  useEffect(() => {
  }, []);

  return (
    <FormLayout
      id={id}
      title={typeName}
      addTitlePrefix={"上传"}
      form={form}
      moduleUrl={modulesUrl.docDoc}
      getData={(data:Doc)=>{
        hooksSet(setData, data)
      }}
      jumpPage={modulesUrl.docDoc + "/" + type}
    >
      <Form.Item key={"type"} name={"type"} hidden={true} initialValue={type}/>
      <ProFormText key="name" name="name" label="名称" placeholder="请输入名称" rules={[{required: true, message: '名称为必填项',}]}/>
      <Form.Item key={"annexIds"} name={"annexIds"} label="上传附件" style={{width:"300px"}} rules={[{required: true, message: '名称为必填项',}]}>
        <Upload name={"annexIds"} form={form} initIds={data?.annexIds} />
      </Form.Item>
      <FormSwitch name="isTop" label="是否置顶" form={form} ></FormSwitch>
      <Edit label={"描述"} name={"description"} required={true} form={form} initialValue={data?.description}/>
    </FormLayout>
  );
};

export default DocForm;
